/* 
 * File:   GameUti.h
 * Author: Vicky.H
 * Email:  eclipser@163.com
 *
 * Created on 2014��3��28��, ����1:06
 */

#ifndef CN_VICKY__GAMEUTI_H
#define	CN_VICKY__GAMEUTI_H

#include "Type.h"

//������
#if defined(WIN32) || defined(WIN64)

class MyLock {
    CRITICAL_SECTION m_Lock;
public:

    MyLock() {
        InitializeCriticalSection(&m_Lock);
    };

    ~MyLock() {
        DeleteCriticalSection(&m_Lock);
    };

    VOID Lock() {
        EnterCriticalSection(&m_Lock);
    };

    VOID Unlock() {
        LeaveCriticalSection(&m_Lock);
    };
};
#elif defined(__linux__)

class MyLock {
    pthread_mutex_t m_Mutex;
public:

    MyLock() {
        pthread_mutex_init(&m_Mutex, NULL);
    };

    ~MyLock() {
        pthread_mutex_destroy(&m_Mutex);
    };

    VOID Lock() {
        pthread_mutex_lock(&m_Mutex);
    };

    VOID Unlock() {
        pthread_mutex_unlock(&m_Mutex);
    };
};
#endif

TID MyGetCurrentThreadID();

#endif	/* CN_VICKY__GAMEUTI_H */

